package org.studiox.graph.common;

import org.studiox.graph.common.exception.GraphException;

import java.util.List;
import java.util.Map;

/** the interface of the common graph */
public interface IGraphWrapper {

  /** init method */
  void open() throws GraphException;

  /** close method */
  void close();

  /**
   * Create new vertex
   *
   * <p>uniq is the unique name to one vertex
   *
   * @param uniq
   * @param type
   * @param createTime
   * @return Vertex ID(Long)
   */
  Long createVertex(String uniq, String type, Long createTime);

  /**
   * Create new vertex without pre-check
   *
   * <p>uniq is the unique name to one vertex
   *
   * @param uniq
   * @param type
   * @param createTime
   * @return Vertex ID(Long)
   */
  Long createVertexNotPreCheck(String uniq, String type, Long createTime);

  /**
   * Update the existed vertex
   *
   * <p>uniq is the unique name to one vertex
   *
   * @param uniq
   * @param type
   * @param createTime
   * @return
   */
  boolean updateVertex(String uniq, String type, Long createTime);

  /**
   * Update the existed vertex, also update the graph edge property
   *
   * <p>oldUniq is the unique name to the old vertex
   *
   * <p>newUniq is the unique name change from the old vertex unique name
   *
   * @param oldUniq
   * @param newUniq
   * @param type
   * @param createTime
   * @return
   */
  boolean updateVertex(String oldUniq, String newUniq, String type, Long createTime);

  /**
   * Soft delete the existed vertices
   *
   * <p>uniq is the unique name to one vertex
   *
   * <p>type could point to multi vertices
   *
   * @param uniq
   * @param type
   * @return
   */
  boolean softDeleteVertices(String uniq, String type);

  /**
   * Recover the deleted vertices
   *
   * <p>uniq is the unique name to one vertex
   *
   * <p>type could point to multi vertices
   *
   * @param uniq
   * @param type
   * @return
   */
  boolean recoverDeletedVertices(String uniq, String type);

  /**
   * Hard delete the existed vertices
   *
   * <p>uniq is the unique name to one vertex
   *
   * <p>type could point to multi vertices
   *
   * @param uniq
   * @param type
   * @return
   */
  boolean hardDeleteVertices(String uniq, String type);

  /**
   * Create new edge
   *
   * <p>uniq is the unique name to one edge
   *
   * @param uniq
   * @param type
   * @param sourceVertexUniq
   * @param targetVertexUniq
   * @param createTime
   * @return Edge ID(String)
   */
  String createEdge(
      String uniq, String type, String sourceVertexUniq, String targetVertexUniq, Long createTime);

  /**
   * Create new edge without pre-check
   *
   * <p>uniq is the unique name to one edge
   *
   * @param uniq
   * @param type
   * @param sourceVertexId
   * @param targetVertexId
   * @param createTime
   * @return Edge ID(String)
   */
  String createEdgeNotPreCheck(
      String uniq, String type, Long sourceVertexId, Long targetVertexId, Long createTime);

  /**
   * Soft delete the existed edges
   *
   * <p>uniq is the unique name to one edge
   *
   * <p>type、sourceVertexUniq and targetVertexUniq could point to multi edges
   *
   * @param uniq
   * @param type
   * @param sourceVertexUniq
   * @param targetVertexUniq
   * @return
   */
  boolean softDeleteEdges(
      String uniq, String type, String sourceVertexUniq, String targetVertexUniq);

  /**
   * Recover the deleted edges
   *
   * <p>uniq is the unique name to one edge
   *
   * <p>type、sourceVertexUniq and targetVertexUniq could point to multi edges
   *
   * @param uniq
   * @param type
   * @param sourceVertexUniq
   * @param targetVertexUniq
   * @return
   */
  boolean recoverDeletedEdges(
      String uniq, String type, String sourceVertexUniq, String targetVertexUniq);

  /**
   * Hard delete the existed edges
   *
   * <p>uniq is the unique name to one edge
   *
   * <p>type、sourceVertexUniq and targetVertexUniq could point to multi edges
   *
   * @param uniq
   * @param type
   * @param sourceVertexUniq
   * @param targetVertexUniq
   * @return
   */
  boolean hardDeleteEdges(
      String uniq, String type, String sourceVertexUniq, String targetVertexUniq);

  /**
   * Get the chosen vertex by uniq
   *
   * <p>uniq is the unique name to one vertex
   *
   * @param uniq
   * @return
   */
  GraphVertex getVertex(String uniq);

  /**
   * Get some vertices by type property
   *
   * <p>type is the property value belong to the vertex
   *
   * @param type
   * @return
   */
  List<GraphVertex> getVerticesByType(String type);

  /**
   * Get the chosen edge by uniq
   *
   * <p>uniq is the unique name to one edge
   *
   * @param uniq
   * @return
   */
  GraphEdge getEdge(String uniq);

  /**
   * Get the chosen edges
   *
   * <p>type、sourceVertexUniq and targetVertexUniq could point to multi edges
   *
   * @param type
   * @param sourceVertexUniq
   * @param targetVertexUniq
   * @return
   */
  List<GraphEdge> getEdges(String type, String sourceVertexUniq, String targetVertexUniq);

  /**
   * Get source vertices and edges
   *
   * <p>vertexUniq is the unique value to the vertex
   *
   * @param vertexUniq
   * @return
   */
  Map<GraphEdge, GraphVertex> getSourceVertexEdgeMap(String vertexUniq);

  /**
   * Get target vertices and edges
   *
   * <p>vertexUniq is the unique value to the vertex
   *
   * @param vertexUniq
   * @return
   */
  Map<GraphEdge, GraphVertex> getTargetVertexEdgeMap(String vertexUniq);

  /**
   * Get Graph Impact Info
   *
   * <p>vertexUniq is the unique value to the vertex
   *
   * <p>when depth <= 0, means traverse the entire graph
   *
   * <p>when depth > 0, means the define depth result
   *
   * <p>skipDeleted=false, return all the vertices(include the deleted vertices)
   *
   * <p>skipDeleted=true, return undeleted the vertices
   *
   * @param vertexUniq
   * @param depth
   * @param skipDeleted
   * @return
   */
  GraphLineage getImpact(String vertexUniq, Integer depth, boolean skipDeleted);

  /**
   * Get Graph Lineage Info
   *
   * <p>vertexUniq is the unique value to the vertex
   *
   * <p>when depth <= 0, means traverse the entire graph
   *
   * <p>when depth > 0, means the define depth result
   *
   * <p>skipDeleted=false, return all the vertices(include the deleted vertices)
   *
   * <p>skipDeleted=true, return undeleted the vertices
   *
   * @param vertexUniq
   * @param depth
   * @param skipDeleted
   * @return
   */
  GraphLineage getLineage(String vertexUniq, Integer depth, boolean skipDeleted);

  /**
   * Get Both Graph Impact and Lineage Info
   *
   * <p>vertexUniq is the unique value to the vertex
   *
   * <p>when depth <= 0, means traverse the entire graph
   *
   * <p>when depth > 0, means the define depth result
   *
   * <p>skipDeleted=false, return all the vertices(include the deleted vertices)
   *
   * <p>skipDeleted=true, return undeleted the vertices
   *
   * @param vertexUniq
   * @param depth
   * @param skipDeleted
   * @return
   */
  GraphLineage getFullLineage(String vertexUniq, Integer depth, boolean skipDeleted);
}
